package domain;

import java.io.Serializable;
import java.util.ArrayList;

public class Notes implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = -1998449240264913712L;
    private ArrayList<String> notes            = new ArrayList<String>();

    public Notes() {
    }

    /**
     * Returns if there are any notes.
     * 
     * @return true if isEmpty();
     */
    public boolean isEmpty() {
        return notes.isEmpty();
    }

    /**
     * Add a note.
     * 
     * @param text
     */
    public void addNote(String text) {
        notes.add(text);
    }

    /**
     * Get a note.
     * 
     * @param noteNum
     *            must exist
     * @return note
     */
    public String getNote(int noteNum) {
        return notes.get(noteNum - 1);
    }

    /**
     * Delete a note.
     * 
     * @param noteNum
     *            must exists.
     */
    public void delNote(int noteNum) {
        notes.remove(noteNum - 1);
    }

    /**
     * Show all Notes.
     * 
     * @return all notes.
     */
    public String showAllNotes() {
        return showAllNotes(null);
    }

    /**
     * Show all Notes that contains <word>.
     * 
     * @param word
     *            search pattern.
     * @return all notes.
     */
    public String showAllNotes(String word) {
        int i = 0;
        StringBuilder sb = new StringBuilder();
        for (String note : notes) {
            if (word == null || note.contains(word)) {
                sb.append(++i + " - ");
                sb.append(note);
                sb.append("\n");
            }
        }
        return sb.toString();
    }

    /**
     * Return all notes separated by a "," and delimited by "[" and "]".
     * 
     * @return toString
     */
    public String toString() {
        return notes.toString();
    }
}
